
# this is some stuff for youthgive specifically that is in base_utils but seems to crash
# it is a mess anyway

    #########################################################################
    # utilities
    # xxx move this
    #########################################################################

	# dump all an object's attributes for inspection purposes
	# creates a div with the specified name to which it appends _# where # is the id of the object
	def show_details(object, divname)
	 #return "foo"
	#return nil if !object
		if  object && @session[:username] && (@session[:username] == "testbrad" || @session[:username] == "testuser" || @session[:username] == "anselm"  )
			write '<script>var current_status = evenodd; evenodd=true;</script>'
			write '<a href="#" class="button" onclick=\'showDiv("' + divname + '_' + object.id.to_s + '"); return false;\'>show details</a>'
			write '<div id="' + divname + '_' + object.id.to_s + '" class="db-details">'
			write '<a href="#" class="button" onclick=\'hideDiv("' + divname + '_' + object.id.to_s + '"); return false;\'>hide details</a><br>'
			write '<table>'
			write '<tr class="oddrow"><td><span class="db-details-fieldname">ID</span></td><td> <span class="db-details-fieldvalue">' + object.id.to_s + '</span></td></tr>'
			write '<tr class="evenrow"><td><span class="db-details-fieldname">Type</span></td><td> <span class="db-details-fieldvalue">' + object.class.to_s + '</span></td></tr>'
			object.class.new.attribute_names.each do |x|
				write '<script>evenodd = !evenodd; if (evenodd) document.write(\'<tr class="evenrow">\'); else document.write(\'<tr class="oddrow">\'); </script>'
				write '<td><span class="db-details-fieldname">' + x +'</span></td><td> <span class="db-details-fieldvalue">'
				write object.send(x)
				write '</span> </td></tr>'
			end
			write '</table></div>'
			write '<script>hideDiv("' + divname + '_' + object.id.to_s + '"); evenodd = current_status ;</script>'
		end
	end
	
	# display a table of alternating style rows
	# takes a collection of objects, a list of column-headers space-separated, and a list of corresponding fields space-separated
	def zebra_table(objects, headers, fields )
	    #return "" 
return if !objects
		hdrs = headers.split("|")
		flds = fields.split("|")
		write '<script>var current_status = evenodd; evenodd=true;</script>'
		write '<thead>'
		hdrs.each do |hdr|
			if hdr != "Details" || (@session[:username] && (@session[:username] == "testbrad" || @session[:username] == "testuser" || @session[:username] == "anselm"  ))
				write '<th>' + hdr + '</th>'
			end
		end
		write '</thead><tbody>'
		objects.each do |obj|
			objtyp = obj.class.to_s
			write '<script>evenodd = !evenodd;  if (evenodd) document.write(\'<tr class="evenrow">\'); else document.write(\'<tr class="oddrow">\'); </script>'
			flds.each do |fld| 
				if fld == "details" 
					 write '<td valign="center" width="100px">' if @session[:username] && (@session[:username] == "testbrad" || @session[:username] == "testuser" || @session[:username] == "anselm"  )
				else 
					write '<td valign="top">'
				end
				
				value = obj.send fld if fld != "details"
				typ = "String"
				typ = value.class.to_s if value
				if fld == "depiction" && value && value.length >1
					if objtyp == "Bookmark"
						write '<a href="/' + obj.title + '"><img src="/' + obj.title + '/.' + obj.title + '.jpg" width="80"></img></a>' 
					else
						write '<img src="' + value +'" border=0 width="40px"/>' 
					end
				elsif typ == "User"
					name = value.login
					write '<a href="/' + name + '">' + name + '</a>'
				elsif fld == "details"
					show_details(obj, "details") 
				elsif fld == "total_donations"
					write("$" ) if value
					write( value) if value
				elsif fld == "name" || fld == "title" || fld == "login"
					if objtyp =="Group"
						write '<a href="/'  + obj.uid + '">' + value + '</a>' 
					elsif objtyp =="User"
						write '<a href="/'  + value + '">' + value + '</a>' 
					elsif objtyp =="Bookmark"
						write '<a href="/'  + value + '">' + value + '</a>' 
					elsif objtyp == "Nonpros" 
						write '<a href="/catalogue/'  + obj.id.to_s + '">' + value + '</a>' 
					else 
						write  value
					end
				elsif objtyp == "Account" && fld == "ein"
					  donor = value
					  if donor 
					     donor = User.find_by_id(donor) 
					     donor = donor.login if donor
					  else
					  	 donor = "anonymous"
					  end
					  write donor
				else write  value if value && !(fld == "selected" && value == "Not Selected") #fld + ": " +
				end
				 # write ' ' + value.type.to_s if value
				write '</td>'
			end
			write '</tr>'
		end
		write '</tbody>'
		write '<script>evenodd = current_status ;</script>'
	end
	
	
	@default_depiction= '/images/cat-glyph.gif'
	def user_pic_or_default(user_pic) 
		def_pic =  '/images/cat-glyph.gif' # @default_depiction
		def_pic = user_pic if user_pic and user_pic.length >1
		return def_pic
	end
